<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>综合案例-随机图片</title>
    <script src="../js/jquery-3.3.1.min.js"></script>
</head>
<body>
<!-- 小图 -->
<div style="background-color:red;border: dotted; height: 50px; width: 50px">
    <img src="img/01.jpg" id="small" style="width: 50px; height: 50px;">
</div>
<!-- 大图 -->
<div style="border: double ;width: 400px; height: 400px; position: absolute; left: 500px; top:10px">
    <img src="" id="big" style="width: 400px; height: 400px; display:none;">
</div>

<!-- 开始和结束按钮 -->
<input id="startBtn" type="button" style="width: 150px;height: 150px; font-size: 20px" value="开始">
<input id="stopBtn" type="button" style="width: 150px;height: 150px; font-size: 20px" value="停止">
</body>
<script src="js/jquery-3.3.1.min.js"></script>
<script>
    //1.准备一个数组
    let imgs = [
        "img/01.jpg",
        "img/02.jpg",
        "img/03.jpg",
        "img/04.jpg",
        "img/05.jpg",
        "img/06.jpg",
        "img/07.jpg",
        "img/08.jpg",
        "img/09.jpg",
        "img/10.jpg"];
        let count = 0;
        let time = null;
        let imgSrc = "";
        $("#startBtn").click(function () {
                $("#startBtn").prop("disabled",true);
                $("#stopBtn").prop("disabled",false);
                time =setInterval(function () {
                    let index=count % imgs.length;
                  imgSrc=  imgs[index];
                  $("#small").prop("src",imgSrc);
                  count++;
                },10);
        });

        $("#stopBtn").click(function () {
            clearInterval(time);
            $("#startBtn").prop("disabled", false);
            $("#stopBtn").prop("disabled", true);
            $("#big").prop("src",imgSrc);
            $("#big").prop("style","width : 400px ;height :400px;");
        });
</script>
</html>
